package com.xunjing.order.controller;

import java.util.List;
import java.util.Arrays;
import javax.servlet.http.HttpServletResponse;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xunjing.common.log.annotation.Log;
import com.xunjing.common.log.enums.BusinessType;
import com.xunjing.common.security.annotation.RequiresPermissions;
import com.xunjing.order.domain.SoOrders;
import com.xunjing.order.service.ISoOrdersService;
import com.xunjing.common.core.web.controller.BaseController;
import com.xunjing.common.core.web.domain.AjaxResult;
import com.xunjing.common.core.utils.poi.ExcelUtil;
import com.xunjing.common.core.web.page.TableDataInfo;

/**
 * 订单测试Controller
 *
 * @author zhangyt
 * @date 2024-04-01
 */
@RestController
@RequestMapping("/orders")
public class SoOrdersController extends BaseController {
    @Autowired
    private ISoOrdersService soOrdersService;

    /**
     * 查询订单测试列表
     */
    @RequiresPermissions("order:orders:list")
    @GetMapping("/list")
    public TableDataInfo list(SoOrders soOrders) {
        startPage();
//        soOrders.setFlag("202404");
//         List<SoOrders> list = soOrdersService.selectSoOrdersList(soOrders);
        LambdaQueryWrapper<SoOrders> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SoOrders::getFlag,"202404");
        //wrapper.between(SoOrders::getFlag, "202312","202404");
        List<SoOrders> list = soOrdersService.list(wrapper);
        return getDataTable(list);
    }

    /**
     * 导出订单测试列表
     */
    @RequiresPermissions("order:orders:export")
    @Log(title = "订单测试", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SoOrders soOrders) {
        List<SoOrders> list = soOrdersService.selectSoOrdersList(soOrders);
        ExcelUtil<SoOrders> util = new ExcelUtil<SoOrders>(SoOrders.class);
        util.exportExcel(response, list, "订单测试数据");
    }

    /**
     * 获取订单测试详细信息
     */
    @RequiresPermissions("order:orders:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(soOrdersService.getById(id));
    }

    /**
     * 新增订单测试
     */
    @RequiresPermissions("order:orders:add")
    @Log(title = "订单测试", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SoOrders soOrders) {
        return toAjax(soOrdersService.save(soOrders));
    }

    /**
     * 修改订单测试
     */
    @RequiresPermissions("order:orders:edit")
    @Log(title = "订单测试", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SoOrders soOrders) {
        return toAjax(soOrdersService.updateById(soOrders));
    }

    /**
     * 删除订单测试
     */
    @RequiresPermissions("order:orders:remove")
    @Log(title = "订单测试", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(soOrdersService.removeByIds(Arrays.asList(ids)));
    }
}
